import '../public/index'
import url from '../data/url'
import request from '../data/request'
import { tableConfig } from '../data/config'
import store from 'store'

const base          = url.base,
      getNoticeList = request.getNoticeList;

let table

// 初始化表格
table = $('#table').bootstrapTable($.extend({}, tableConfig, {
  url: base + getNoticeList,
  queryParams: function (params) {
    return $.extend({
      currentPage : params.pageNumber,
      pageSize    : params.pageSize},
      $('#searchForm').serializeObject())
  },
  columns: [
    {
      field: 'title',
      title: '标题',
      valign: 'middle'
    }, {
      field: 'headStr',
      title: '头部',
      valign: 'middle'
    }, {
      field: 'footerStr',
      title: '备注',
      valign: 'middle'
    }, {
      field: 'action',
      valign: 'middle',
      align: 'center',
      width: '200px',
      title: '操作',
      formatter: function(index, row) {
        return `<div class="btn-group">
                      <button data-id="${ row.idStr }" type="button" class="btn btn-default btn-modify">编辑</button>
                </div>`
      }
    }]
}))

// 搜索
$('#search-btn').on('click', (e) => {
  e.preventDefault();

  table.bootstrapTable('refresh', {
    query: $.extend({
      currentPage : 1,
    }, $('#searchForm').serializeObject())
  })
})


// 编辑
$(document).on('click', '#table .btn-modify', (e) => {
  e.preventDefault()

  console.log('编辑')

  let id = $(e.target).attr('data-id');

  window.location.href = './modify.html?id=' + id;
})